package com.ysx.oa.clazz.controller;

import com.ysx.oa.clazz.bean.ClazzBean;
import com.ysx.oa.clazz.service.ClazzService;
import com.ysx.oa.user.bean.UserBean;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 李伟伟
 * @date 2021/11/22 15:24
 */
@RestController
@RequestMapping("/clazz")
public class ClazzController {

    @Autowired
    private ClazzService clazzService;


    // http://localhost:8080/kaoqin/clazz/updateClazz
    @RequestMapping(value = "/updateClazz" ,method =RequestMethod.POST)
    @CrossOrigin
    public Map<String ,Object> updateClazz(@RequestBody ClazzBean clazzBean){
        Map<String,Object> map=new HashMap();
        Integer i = clazzService.updateClazz(clazzBean);

        if(i==0){
            map.put("code",500);
            map.put("message","failure");
        }else{
            map.put("code",200);
            map.put("message","success");
        }
        return map;
    }

    // http://localhost:8080/kaoqin/clazz/deleteClazz
    @RequestMapping(value="/deleteClazz",method = RequestMethod.POST)
    @CrossOrigin
    public Map<String,Object> deleteClazz(@RequestBody ClazzBean clazzBean){
        Map<String,Object> map=new HashMap();
        Integer ids = clazzService.deleteClazz(clazzBean);

        map.put("code",200);
        map.put("message","ids");
        return map;

    }

    // http://localhost:8080/kaoqin/clazz/add
    @RequestMapping(value="/add",method = RequestMethod.POST)
    @CrossOrigin
    public Map<String,Object> addClazz(@RequestBody ClazzBean clazz, HttpServletRequest request){
        Integer userId = (Integer)request.getSession().getAttribute("userId");
        System.out.println(userId);

        Map<String,Object> map=new HashMap();
        clazzService.addClazz(clazz);
        map.put("code",200);
        map.put("message","success");
        return map;
    }
    // http://localhost:8080/kaoqin/clazz/findAllClazz
    @CrossOrigin
    @RequestMapping(value = "/findAllClazz" ,method = RequestMethod.POST)
    public Map<String,Object> findAllClazz(){
    List<ClazzBean> list=clazzService.findAllClazz();
    Map<String,Object> map=new HashMap();
        map.put("code",200);
        map.put("message","success");
        map.put("data",list);
        return  map;
    }

    // http://localhost:8080/kaoqin/clazz/findStudentMassageByClazzId?id=202107
    @CrossOrigin
    @RequestMapping(value = "/findStudentMassageByClazzId",method = RequestMethod.GET)
    public Map<String ,Object> findStudentMassageByClazzId( Integer id){
        List<UserBean> list= clazzService.findStudentMassageByClazzId(id);
        Map<String,Object> map=new HashMap();

        map.put("code",200);
        map.put("message","success");
        map.put("data",list);
        return map;
    }

    // http://localhost:8080/kaoqin/clazz/findStudentMassageByClazzId?id=202107
    @CrossOrigin
    @RequestMapping(value = "/findTeacherMassageByClazzId",method = RequestMethod.GET)
    public Map<String ,Object> findTeacherMassageByClazzId(Integer id){
        List<UserBean> list= clazzService.findTeacherMassageByClazzId(id);
        Map<String,Object> map=new HashMap();

        map.put("code",200);
        map.put("message","success");
        map.put("data",list);
        return map;
    }






}
